Skip to content

Extract mixin from PV and EV component managers#1403

Merged
simonvoelcker merged 1 commit into
frequenz-floss:v1.x.xfrom
simonvoelcker:extract-set-power
May 22, 2026
Merged

Extract mixin from PV and EV component managers#1403
simonvoelcker merged 1 commit into
frequenz-floss:v1.x.xfrom
simonvoelcker:extract-set-power

Conversation

@simonvoelcker
Copy link
Copy Markdown
Contributor

@simonvoelcker simonvoelcker commented May 15, 2026

PV inverter manager, EV charger manager and also battery manager have similar functionality for setting power levels in the microgrid API. These have drifted apart to different degrees, especially the battery manager implementation differs a lot. The other two were close enough to extract them into a util function. This will be reusable when we introduce a similar manager for steam boilers.

@simonvoelcker simonvoelcker self-assigned this May 15, 2026
@github-actions github-actions Bot added the part:microgrid Affects the interactions with the microgrid label May 15, 2026
@simonvoelcker simonvoelcker added the cmd:skip-release-notes It is not necessary to update release notes for this PR label May 15, 2026
@simonvoelcker simonvoelcker force-pushed the extract-set-power branch 2 times, most recently from 4b9e90f to e28fc25 Compare May 15, 2026 13:22
@simonvoelcker simonvoelcker marked this pull request as ready for review May 15, 2026 13:27
@simonvoelcker simonvoelcker requested a review from a team as a code owner May 15, 2026 13:27
@simonvoelcker simonvoelcker requested review from ela-kotulska-frequenz and removed request for a team May 15, 2026 13:27
Copy link
Copy Markdown
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I wonder if it makes more sense to just include it in ComponentManager and make BatteryManager override it if it needs something special, instead of introducing a separate mixin.

Will leave @shsms the final approval as he's more familiar with this code.

@llucax llucax requested a review from shsms May 19, 2026 07:32
@simonvoelcker
Copy link
Copy Markdown
Contributor Author

@llucax I was considering that, but the battery manager is structured very differently. The closest match to the extracted method, _set_api_power, is _set_distributed_power, and you will find that its signature already differs quite a lot.

Copy link
Copy Markdown
Contributor

@shsms shsms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use relative import paths, and one optional comment.

"""Mixin for setting component powers via microgrid API."""

@staticmethod
async def _set_api_power( # pylint: disable=too-many-locals,too-many-arguments
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, but I wonder if this should just be a function instead, the mixin is a lot of machinary for a static method that doesn't need self.

shsms
shsms previously approved these changes May 21, 2026
@github-project-automation github-project-automation Bot moved this from To do to Review approved in Python SDK Roadmap May 21, 2026
@shsms
Copy link
Copy Markdown
Contributor

shsms commented May 21, 2026

looks like CI is failing

PV inverter manager, EV charger manager and also battery manager have similar functionality for setting power levels in the microgrid API. These have drifted apart to different degrees, especially the battery manager implementation differs a lot. The other two were close enough to extract them into a mixin. This will be reusable when we introduce a similar manager for steam boilers.

Signed-off-by: Simon Völcker <simon.voelcker@frequenz.com>
@simonvoelcker simonvoelcker enabled auto-merge May 22, 2026 08:48
@simonvoelcker simonvoelcker requested a review from shsms May 22, 2026 08:48
@simonvoelcker simonvoelcker added this pull request to the merge queue May 22, 2026
Merged via the queue into frequenz-floss:v1.x.x with commit 3a94ed0 May 22, 2026
8 checks passed
@simonvoelcker simonvoelcker deleted the extract-set-power branch May 22, 2026 11:54
@github-project-automation github-project-automation Bot moved this from Review approved to Done in Python SDK Roadmap May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:microgrid Affects the interactions with the microgrid

Projects

Development

Successfully merging this pull request may close these issues.

3 participants